"""响应模型定义模块"""

from typing import Optional, List, Any
from datetime import datetime

from pydantic import BaseModel, Field

from .enums import DetectionStatus, DetectionPlatform


class BaseResponse(BaseModel):
    """基础响应模型"""
    
    success: bool = Field(True, description="是否成功")
    message: str = Field("操作成功", description="响应消息")
    timestamp: datetime = Field(default_factory=datetime.now, description="响应时间")


class ErrorResponse(BaseResponse):
    """错误响应模型"""
    
    success: bool = Field(False, description="是否成功")
    error_code: str = Field(..., description="错误代码")
    detail: Optional[str] = Field(None, description="错误详情")


class TextDetectionResponse(BaseResponse):
    """文本检测响应模型"""
    
    task_id: str = Field(..., description="任务ID")
    status: DetectionStatus = Field(..., description="检测状态")
    platform: DetectionPlatform = Field(..., description="检测平台")
    similarity_rate: Optional[float] = Field(None, description="相似度", ge=0.0, le=1.0)
    report_url: Optional[str] = Field(None, description="报告下载链接")
    created_at: datetime = Field(..., description="创建时间")
    updated_at: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        use_enum_values = True


class BatchDetectionResponse(BaseResponse):
    """批量检测响应模型"""
    
    batch_id: str = Field(..., description="批量任务ID")
    total_count: int = Field(..., description="总任务数")
    completed_count: int = Field(0, description="已完成数")
    failed_count: int = Field(0, description="失败数")
    tasks: List[TextDetectionResponse] = Field([], description="子任务列表")


class DetectionHistoryResponse(BaseResponse):
    """检测历史响应模型"""
    
    total: int = Field(..., description="总记录数")
    page: int = Field(..., description="当前页码")
    size: int = Field(..., description="每页数量")
    items: List[TextDetectionResponse] = Field(..., description="历史记录列表")


class PlatformsResponse(BaseResponse):
    """支持平台响应模型"""
    
    platforms: List[dict] = Field(..., description="支持的检测平台列表")


class HealthResponse(BaseModel):
    """健康检查响应模型"""
    
    status: str = Field("healthy", description="服务状态")
    version: str = Field(..., description="应用版本")
    timestamp: datetime = Field(default_factory=datetime.now, description="检查时间")
    services: dict = Field(default_factory=dict, description="服务状态详情")


class DataResponse(BaseResponse):
    """通用数据响应模型"""
    
    data: Any = Field(None, description="响应数据") 